﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebServerConnectorDll;

namespace WebServerConnectorDll
{
    public class API
    {
        #region Login.php
        public static HttpResponse Login(String Username, String Password)
        {
            String data = "Username=" + Username + "&Password=" + Password;
            return Conn.Post("Login.php", data);
        }
        #endregion

        #region Province.php
        public static HttpResponse SelectProvince()
        {
            return Conn.Post("Province.php?Method=Select");
        }

        public static HttpResponse DeleteProvince(List<int> ProvinceUIDs)
        {
            String data = "";
            for (int i = 0; i < ProvinceUIDs.Count; i++)
            {
                data += ProvinceUIDs[i];
                if(i != (ProvinceUIDs.Count-1))
                {
                    data += ",";
                }
            }
            
            return Conn.Post("Province.php?Method=Delete", data);
        }

        public static HttpResponse InsertProvince(CProvince Province)
        {
            return Conn.Post("Province.php?Method=Insert", Province.ToInsertString());
        }

        public static HttpResponse UpdateProvince(CProvince Province, int ProvinceUID)
        {
            String data = Province.ToUpdateString() + "#" + ProvinceUID;
            return Conn.Post("Province.php?Method=Update", data);
        }
        #endregion

        #region City.php
        public static HttpResponse SelectCity(int ProvinceUID)
        {
            return Conn.Post("City.php?Method=Select", ProvinceUID.ToString());
        }

        public static HttpResponse DeleteCity(List<int> CityUIDs)
        {
            String data = "";
            for (int i = 0; i < CityUIDs.Count; i++)
            {
                data += CityUIDs[i];
                if (i != (CityUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("City.php?Method=Delete", data);
        }

        public static HttpResponse InsertCity(CCity City)
        {
            return Conn.Post("City.php?Method=Insert", City.ToInsertString());
        }

        public static HttpResponse UpdateCity(CCity City, int CityUID)
        {
            String data = City.ToUpdateString() + "#" + CityUID;
            return Conn.Post("City.php?Method=Update", data);
        }
        #endregion

        #region Office.php
        public static HttpResponse SelectOffice(int ProvinceUID, int CityUID)
        {
            return Conn.Post("Office.php?Method=Select", "ProvinceUID=" + ProvinceUID + "&CityUID=" + CityUID);
        }

        public static HttpResponse DeleteOffice(List<int> OfficeUIDs)
        {
            String data = "";
            for (int i = 0; i < OfficeUIDs.Count; i++)
            {
                data += OfficeUIDs[i];
                if (i != (OfficeUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("Office.php?Method=Delete", data);
        }

        public static HttpResponse InsertOffice(COffice Office)
        {
            return Conn.Post("Office.php?Method=Insert", Office.ToInsertString());
        }

        public static HttpResponse UpdateOffice(COffice Office, int UID)
        {
            String data = Office.ToUpdateString() + "#" + UID;
            return Conn.Post("Office.php?Method=Update", data);
        }
        #endregion

        #region PersonnelGroup.php
        public static HttpResponse SelectPersonnelGroup()
        {
            return Conn.Post("PersonnelGroup.php?Method=Select");
        }

        public static HttpResponse UpdatePersonnelGroup(CPersonnelGroup PersonnelGroup, int UID)
        {
            String data = PersonnelGroup.ToUpdateString() + "#" + UID;
            return Conn.Post("PersonnelGroup.php?Method=Update", data);
        }
        #endregion

        #region PersonnelGroupPermission
        public static HttpResponse SelectPersonnelGroupPermission(int PersonnelGroupUID)
        {
            String data = "PersonnelGroupUID=" + PersonnelGroupUID;
            return Conn.Post("PersonnelGroupPermission.php?Method=Select", data);
        }

        public static HttpResponse InsertPersonnelGroupPermission(List<CPersonnelGroupPermission> list)
        {
            String data = "";

            for(int i = 0; i< list.Count; i++)
            {
                data += list[i].ToInsertString();
                if(i != (list.Count-1))
                {
                    data += "-";
                }
            }

            return Conn.Post("PersonnelGroupPermission.php?Method=Insert", data);
        }

        public static HttpResponse DeletePersonnelGroupPermission(int PersonnelGroupUID)
        {
            return Conn.Post("PersonnelGroupPermission.php?Method=Delete", PersonnelGroupUID.ToString());
        }
        #endregion

        #region Permission
        public static HttpResponse SelectPermission()
        {
            return Conn.Post("Permission.php?Method=Select");
        }
        #endregion

        #region Personnel
        public static HttpResponse SelectPersonnel(int Page=1)
        {
            return Conn.Post("Personnel.php?Method=Select&Page=" + Page);
        }
        public static HttpResponse SelectCountPersonnel()
        {
            return Conn.Post("Personnel.php?Method=SelectCount");
        }
        public static HttpResponse InsertPersonnel(CPersonnel Personnel)
        {
            return Conn.Post("Personnel.php?Method=Insert", Personnel.ToInsertString());
        }
        public static HttpResponse UpdatePersonnel(CPersonnel Personnel, int UID)
        {
            String data = Personnel.ToUpdateString() + "#" + UID;
            return Conn.Post("Personnel.php?Method=Update", data);
        }
        public static HttpResponse DeletePersonnel(List<int> PersonnelUIDs)
        {
            String data = "";
            for (int i = 0; i < PersonnelUIDs.Count; i++)
            {
                data += PersonnelUIDs[i];
                if (i != (PersonnelUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("Personnel.php?Method=Delete", data);
        }
        #endregion

        #region VIP.php
        public static HttpResponse SelectVIP()
        {
            return Conn.Post("VIP.php?Method=Select");
        }

        public static HttpResponse DeleteVIP(List<int> VIPUIDs)
        {
            String data = "";
            for (int i = 0; i < VIPUIDs.Count; i++)
            {
                data += VIPUIDs[i];
                if (i != (VIPUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("VIP.php?Method=Delete", data);
        }

        public static HttpResponse InsertVIP(CVIP VIP)
        {
            return Conn.Post("VIP.php?Method=Insert", VIP.ToInsertString());
        }

        public static HttpResponse UpdateVIP(CVIP VIP, int VIPUID)
        {
            String data = VIP.ToUpdateString() + "#" + VIPUID;
            return Conn.Post("VIP.php?Method=Update", data);
        }
        #endregion

        #region Coupon.php
        public static HttpResponse SelectCoupon()
        {
            return Conn.Post("Coupon.php?Method=Select");
        }

        public static HttpResponse DeleteCoupon(List<int> CouponUIDs)
        {
            String data = "";
            for (int i = 0; i < CouponUIDs.Count; i++)
            {
                data += CouponUIDs[i];
                if (i != (CouponUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("Coupon.php?Method=Delete", data);
        }

        public static HttpResponse InsertCoupon(CCoupon Coupon)
        {
            return Conn.Post("Coupon.php?Method=Insert", Coupon.ToInsertString());
        }

        public static HttpResponse UpdateCoupon(CCoupon Coupon, int CouponUID)
        {
            String data = Coupon.ToUpdateString() + "#" + CouponUID;
            return Conn.Post("Coupon.php?Method=Update", data);
        }
        #endregion

        #region Device.php
        public static HttpResponse SelectDevice(int OfficeUID)
        {
            return Conn.Post("Device.php?Method=Select", OfficeUID.ToString());
        }

        public static HttpResponse DeleteDevice(List<int> DeviceUIDs)
        {
            String data = "";
            for (int i = 0; i < DeviceUIDs.Count; i++)
            {
                data += DeviceUIDs[i];
                if (i != (DeviceUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("Device.php?Method=Delete", data);
        }

        public static HttpResponse InsertDevice(CDevice Device)
        {
            return Conn.Post("Device.php?Method=Insert", Device.ToInsertString());
        }

        public static HttpResponse UpdateDevice(CDevice Device, int DeviceUID)
        {
            String data = Device.ToUpdateString() + "#" + DeviceUID;
            return Conn.Post("Device.php?Method=Update", data);
        }
        #endregion

        #region DeviceType.php
        public static HttpResponse SelectDeviceType()
        {
            return Conn.Post("DeviceType.php?Method=Select");
        }

        public static HttpResponse DeleteDeviceType(List<int> DeviceTypeUIDs)
        {
            String data = "";
            for (int i = 0; i < DeviceTypeUIDs.Count; i++)
            {
                data += DeviceTypeUIDs[i];
                if (i != (DeviceTypeUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("DeviceType.php?Method=Delete", data);
        }

        public static HttpResponse InsertDeviceType(CDeviceType DeviceType)
        {
            return Conn.Post("DeviceType.php?Method=Insert", DeviceType.ToInsertString());
        }

        public static HttpResponse UpdateDeviceType(CDeviceType DeviceType, int DeviceTypeUID)
        {
            String data = DeviceType.ToUpdateString() + "#" + DeviceTypeUID;
            return Conn.Post("DeviceType.php?Method=Update", data);
        }
        #endregion

        #region DeviceTime.php
        public static HttpResponse SelectDeviceTime(int DeviceUID)
        {
            String data = "DeviceUID=" + DeviceUID;

            return Conn.Post("DeviceTime.php?Method=Select", data);
        }

        public static HttpResponse DeleteDeviceTime(int DeviceUID)
        {
            return Conn.Post("DeviceTime.php?Method=Delete", DeviceUID.ToString());
        }

        public static HttpResponse InsertDeviceTime(List<CDeviceTime> list)
        {
            String data = "";

            for (int i = 0; i < list.Count; i++)
            {
                data += list[i].ToInsertString();
                if (i != (list.Count - 1))
                {
                    data += "-";
                }
            }

            return Conn.Post("DeviceTime.php?Method=Insert", data);
        }
        #endregion

        #region User.php
        public static HttpResponse SelectUser(int OfficeUID)
        {
            return Conn.Post("User.php?Method=Select", OfficeUID.ToString());
        }

        public static HttpResponse DeleteUser(List<String> UserUIDs)
        {
            String data = "";
            for (int i = 0; i < UserUIDs.Count; i++)
            {
                data += UserUIDs[i];
                if (i != (UserUIDs.Count - 1))
                {
                    data += ",";
                }
            }

            return Conn.Post("User.php?Method=Delete", data);
        }

        public static HttpResponse InsertUser(CUser User)
        {
            return Conn.Post("User.php?Method=Insert", User.ToInsertString());
        }

        public static HttpResponse UpdateUser(CUser User, int UserUID)
        {
            String data = User.ToUpdateString() + "#" + UserUID;
            return Conn.Post("User.php?Method=Update", data);
        }
        #endregion
    }
}
